---
import config from '@/config';
import { ClientRouter } from 'astro:transitions';
import getPath from '@/utils/getPath';
import getUrl from '@/utils/getUrl';
import '@/styles/global.css';

export interface Props {
  title?: string;
  author?: string;
  description?: string;
  ogImage?: string;
  pubDatetime?: Date;
  modDatetime?: Date;
  canonicalURL?: string;
  scrollSmooth?: boolean;
  discussionNumber?: number;
}

const {
  title = config.title,
  author = config.author,
  description = config.description,
  ogImage,
  canonicalURL = new URL(Astro.url.pathname, Astro.site).href,
  pubDatetime,
  modDatetime,
  scrollSmooth = false,
} = Astro.props;

const socialImageUrl = getUrl(ogImage ?? 'og.png');
---

<!doctype html>
<html lang=`${config.lang ?? "en"}` class={`${scrollSmooth && 'scroll-smooth'}`}>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width" />
    <link rel="icon" type="image/svg+xml" href={getPath('favicon.svg')} />
    <link rel="canonical" href={canonicalURL} />
    <meta name="generator" content={Astro.generator} />

    <!-- General Meta Tags -->
    <title>{title}</title>
    <meta name="title" content={title} />
    <meta name="description" content={description} />
    <meta name="author" content={author} />
    <link rel="sitemap" href={getPath('sitemap-index.xml')} />

    <!-- Open Graph / Facebook -->
    <meta property="og:title" content={title} />
    <meta property="og:description" content={description} />
    <meta property="og:url" content={canonicalURL} />
    <meta property="og:image" content={socialImageUrl} />

    <!-- Article Published/Modified time -->
    {pubDatetime && <meta property="article:published_time" content={pubDatetime.toISOString()} />}
    {modDatetime && <meta property="article:modified_time" content={modDatetime.toISOString()} />}

    <!-- Twitter -->
    <meta property="twitter:card" content="summary_large_image" />
    <meta property="twitter:url" content={canonicalURL} />
    <meta property="twitter:title" content={title} />
    <meta property="twitter:description" content={description} />
    <meta property="twitter:image" content={socialImageUrl} />

    <!-- Google Font -->
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
      href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;0,700;1,400;1,600&display=swap"
      rel="stylesheet"
    />

    <meta name="theme-color" content="" />

    <ClientRouter />

    <script is:inline src={getPath('toggle-theme.js')}></script>
  </head>
  <body>
    <slot />
  </body>
</html>
